<?php include '../init.php';

	if(isset($_GET['id'])&&$_GET['id']>0){
		$id = $_GET['id'];
		$sql = "SELECT * FROM user WHERE id=$id";
		$row = $mysql->getRow($sql);
	}
	
?>
<!DOCTYPE html>
<html>
<head>
	<title>添加管理员</title>
	<link rel="stylesheet" type="text/css" href="<?php echo __PUBLIC__;?>/bootsrap/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<?php echo __PUBLIC__;?>/css/back.css">
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/js/jquery.js"></script>
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/bootsrap/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/validate/jquery.validate.min.js"></script>
	<script type="text/javascript" src="<?php echo __PUBLIC__;?>/validate/localization/messages_zh.min.js"></script>
</head>
<body background="../../public/img/bg4.jpg">
	<div>&nbsp;</div>
	<div>&nbsp;</div>
	<div class="container bg-info">
		<div class="col-md-12">&nbsp;</div>
		<div class="col-md-12">&nbsp;</div>
		<div class="row">
			<?php include '../nav.php'; ?>
		</div>
	</div>
	<div class="container bg-info">
		<div class="col-md-12">&nbsp;</div>
		<div class="col-md-12">&nbsp;</div>
		<div class="row">
			<div class="col-md-12">
				<form action="adminsave.php" id="articleForm" method="post">
					<input type="hidden" name="id" value="<?php if(isset($row['id'])){ echo $row['id'];}?>">
					<div class="form-group">
						<div class="col-md-3"></div>
						<div class="col-md-1">
							<label for="name">管理员</label>
						</div>
						<div class="col-md-5">
							<input type="text" class="form-control" name="username" id="name" placeholder="管理员名称" required="true" value="<?php if(isset($row['username'])){ echo $row['username'];}?>">
						</div>
						<div class="col-md-3"></div>
					</div>
					<div class="col-md-12">&nbsp;</div>
					<div class="form-group">
						<div class="col-md-3"></div>
						<div class="col-md-1">
							<label for="password">密码</label>
						</div>
						<div class="col-md-5">
							<input type="text" class="form-control" name="password" id="password" placeholder="密码" required="true" value="">
						</div>
						<div class="col-md-3"></div>
					</div>
					<div class="col-md-12">&nbsp;</div>
					<div class="form-group">
						<div class="col-md-3"></div>
						<div class="col-md-1">
							<label for="passwordcon">确认密码</label>
						</div>
						<div class="col-md-5">
							<input type="text" class="form-control" name="passwordcon" id="passwordcon" placeholder="确认密码" required="true" value="">
						</div>
						<div class="col-md-3"></div>
					</div>
					<div class="col-md-12">&nbsp;</div>
					<div class="col-md-12">
						<div class="form-group">
							<div class="col-md-4 text-right">
								<button class="btn btn-success" type="submit">保　　存</button>
							</div>
							<div class="col-md-4"></div>
							<div class="col-md-4 text-left">
								<a  href="index.php" class="btn btn-success" type="reset">返　　回</a>
							</div>
						</div>
					</div>
					<div class="col-md-12">&nbsp;</div>
					<div class="col-md-12">&nbsp;</div>
				</form>
				<!--弹出框，默认隐藏-->
				<div class="modal fade bs-example-modal-sm" id="myModal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
				    <div class="modal-dialog modal-sm" role="document">
				      <div class="modal-content">

				        <div class="modal-header">
				          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
				          <h4 class="modal-title" id="mySmallModalLabel">Small modal</h4>
				        </div>
				        <div class="modal-body">
				          ...
				        </div>
				      </div><!-- /.modal-content -->
				    </div><!-- /.modal-dialog -->
				  </div>
				  <!--弹出框结束-->
				<!--AJAX提交表单，保存内容-->
				<script type="text/javascript">
					$('#articleForm').on('submit',function(){
						$.ajax({
							type:'post',
							url:$('#articleForm').attr('action'),
							//表单里面的表单项全部序列化成请求字符串。
							data:$('#articleForm').serialize(),
							dataType:'json',
							success:function(data){
								if(data.code=='000'){
									window.location="adminlist.php"
								}else{
									$('#myModal .modal-body').html(data.msg);
									$('#myModal').modal({'show':true});
								}
							}
						});
						return false;
					});
				</script>
			</div>
		</div>
	</div>
</body>
</html>